package com.zhijian.warehouse.manage.service.impl;

import com.zhijian.warehouse.manage.dao.AccessAioAndroidBingMapper;
import com.zhijian.warehouse.manage.entity.po.AccessAioAndroidBing;
import com.zhijian.warehouse.manage.entity.vo.request.AccessAioAndroidBingSearchVo;
import com.zhijian.warehouse.manage.entity.vo.request.AccessAioAndroidBingSaveOrUpdateVo;
import com.zhijian.warehouse.manage.entity.vo.response.AccessAioAndroidBingVo;
import com.zhijian.warehouse.manage.service.AccessAioAndroidBingService;
import com.zhijian.util.page.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.hutool.core.collection.CollectionUtil;
import com.zhijian.util.AssertUtil;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 一体机感应器-安卓设备ip绑定业务处理层
 * 
 * @author auto
 * @version: 1.0
 * @date 2024-11-13 13:15:23
 */
@Slf4j
@Service
public class AccessAioAndroidBingServiceImpl implements AccessAioAndroidBingService {

	@Autowired
    private AccessAioAndroidBingMapper mapper;

    @Override
    public AccessAioAndroidBing selectById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public AccessAioAndroidBingVo selectVoById(Long id) {
        return mapper.selectVoById(id);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteByIdList(List<Long> idList) {
        if (CollectionUtil.isEmpty(idList)) {
            return;
        }
        mapper.deleteByIdList(idList);
    }

    @Override
    public Long insert(AccessAioAndroidBing accessAioAndroidBing) {
        Date now = new Date();
        accessAioAndroidBing.setCreateTime(now);
        accessAioAndroidBing.setUpdateTime(now);
        return mapper.insert(accessAioAndroidBing) > 0 ? accessAioAndroidBing.getId() : 0L;
    }

    @Override
    public Long insertSelective(AccessAioAndroidBing accessAioAndroidBing) {
        Date now = new Date();
        accessAioAndroidBing.setCreateTime(now);
        accessAioAndroidBing.setUpdateTime(now);
        return mapper.insertSelective(accessAioAndroidBing) > 0 ? accessAioAndroidBing.getId() : 0L;
    }

    @Override
    public boolean update(AccessAioAndroidBing accessAioAndroidBing) {
        Date now = new Date();
        accessAioAndroidBing.setUpdateTime(now);
        return mapper.updateByPrimaryKey(accessAioAndroidBing) != 0;
    }

    @Override
    public boolean updateByPrimaryKeySelective(AccessAioAndroidBing record) {
        Date now = new Date();
        record.setUpdateTime(now);
        return mapper.updateByPrimaryKeySelective(record) != 0;
    }

    @Override
    public boolean save(AccessAioAndroidBingSaveOrUpdateVo saveOrUpdateVo) {
        AccessAioAndroidBing accessAioAndroidBing = new AccessAioAndroidBing();
        BeanUtils.copyProperties(saveOrUpdateVo, accessAioAndroidBing);
        return this.insert(accessAioAndroidBing) != 0;
    }

    @Override
    public boolean modify(AccessAioAndroidBingSaveOrUpdateVo saveOrUpdateVo) {
        AccessAioAndroidBing old = this.selectById(saveOrUpdateVo.getId());
        AssertUtil.notNull(old, "此数据不存在或者已被删除");
        AccessAioAndroidBing accessAioAndroidBing = new AccessAioAndroidBing();
        BeanUtils.copyProperties(saveOrUpdateVo, accessAioAndroidBing);
        return this.update(accessAioAndroidBing);
    }

    @Override
    public AccessAioAndroidBingVo selectOne(AccessAioAndroidBingSearchVo accessAioAndroidBingSearchVo) {
        return mapper.selectOne(accessAioAndroidBingSearchVo);
     }

    @Override
    public Integer count(AccessAioAndroidBingSearchVo accessAioAndroidBingSearchVo) {
        return mapper.count(accessAioAndroidBingSearchVo);
    }

    @Override
    public List<AccessAioAndroidBingVo> selectList(AccessAioAndroidBingSearchVo accessAioAndroidBingSearchVo) {
        return mapper.selectList(accessAioAndroidBingSearchVo);
    }

    @Override
    public Page<AccessAioAndroidBingVo> selectPage(AccessAioAndroidBingSearchVo accessAioAndroidBingSearchVo) {
        AssertUtil.check(Objects.isNull(accessAioAndroidBingSearchVo.getPageNum()) || Objects.isNull(accessAioAndroidBingSearchVo.getPageSize()), "分页参数不能为空");
        //先直接查总数
        int count = count(accessAioAndroidBingSearchVo);
        //分页
        Page<AccessAioAndroidBingVo> page = new Page<>(true, count, accessAioAndroidBingSearchVo.getPageNum(), accessAioAndroidBingSearchVo.getPageSize());
        accessAioAndroidBingSearchVo.setStartIndex(page.getStartIndex());
        page.setPage(true);
        page.setTotalCount(count);
        List<AccessAioAndroidBingVo> responseVos = this.selectList(accessAioAndroidBingSearchVo);
        page.setData(responseVos);
        return page;
    }

    @Override
    public boolean insertBatch(List<AccessAioAndroidBing> entities) {
        return CollectionUtil.isNotEmpty(entities) && mapper.insertBatch(entities) > 0;
    }

    @Override
    public void deleteByCondition(AccessAioAndroidBingSearchVo accessAioAndroidBingSearchVo) {
        //慎重用此方法！！
        mapper.deleteByCondition(accessAioAndroidBingSearchVo);
    }
    
}